package pro.ticktock.base.tree.impl;

import pro.ticktock.base.tree.api.Entry;

import java.util.Objects;
import java.util.Optional;

/**
 * @author lambert
 * @created 18-9-30
 */
public class NodeEntry<K, V> implements Entry<K, V> {
  protected K key;
  protected V value;

  public NodeEntry(K key) {
    this.key = key;
  }

  public NodeEntry(K key, V value) {
    this.key = key;
    this.value = value;
  }

  @Override
  public K getKey() {
    return key;
  }

  @Override
  public V getValue() {
    return value;
  }

  public void setValue(V value) {
    this.value = value;
  }

  public int hashCode() {
    if (key == null) return 0;
    else return key.hashCode();
  }

  public boolean equals(Object o) {
    if (o == null || !(o instanceof Entry)) {
      return false;
    }
    if (Objects.equals(key, ((Entry) o).getKey()) && Objects.equals(value, ((Entry) o).getValue()))
      return true;

    return false;
  }


}
